﻿using System;
using GC_FFW.Common.Abstractions.Interfaces.Helpers;
using GC_FFW.Common.Constants.WinForms;
using GC_FFW.Common.Enums;

namespace GC_FFW.Common.Helpers
{
	public class BrowserDialog : IBrowserDialog
	{
		#region IBrowserDialog Members

		public string ShowFolderBrowserDialog()
		{
			var result = String.Empty;

			var dialog = new System.Windows.Forms.FolderBrowserDialog();

			var dialogResult = dialog.ShowDialog();

			if (dialogResult.Equals(System.Windows.Forms.DialogResult.OK))
				result = dialog.SelectedPath;

			return result;
		}

		/// <summary>
		/// Show WinForms File Browser Dialog
		/// </summary>
		/// <param name="fileDialogFilter">Example "Text Files (.txt)|*.txt|All Files (*.*)|*.*" or "Image Files (*.bmp, *.jpg)|*.bmp;*.jpg"</param>
		/// <returns>Return Selected File Path</returns>
		public string ShowFileBrowserDialog(string fileDialogFilter)
		{
			var result = String.Empty;

			var dialog = new System.Windows.Forms.OpenFileDialog();

			if (!string.IsNullOrWhiteSpace(fileDialogFilter))
				dialog.Filter = fileDialogFilter;

			var dialogResult = dialog.ShowDialog();

			if (dialogResult.Equals(System.Windows.Forms.DialogResult.OK))
				result = dialog.FileName;

			return result;
		}

		public string ShowFileBrowserDialog(FileType fileType)
		{
			switch (fileType)
			{
				case FileType.XML:
					return ShowFileBrowserDialog(OpenFileDialogFilters.XMLFiles);

				default:
					return ShowFileBrowserDialog(OpenFileDialogFilters.AllFiles);
			}
		}

		#endregion
	}
}
